package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.QrtzLocks;
import io.mybatis.example.springboot.service.QrtzLocksService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * QRTZ_LOCKS - 存储的悲观锁信息表
 *
 * @author mkj
 */
@RestController
@RequestMapping("qrtzLockses")
public class QrtzLocksController {

  @Autowired
  private QrtzLocksService qrtzLocksService;

  @PostMapping
  public DataResponse<QrtzLocksDO> save(@RequestBody QrtzLocksDO qrtzLocks) {
    return DataResponse.ok(qrtzLocksService.save( qrtzLocks));
  }

  @GetMapping
  public RowsResponse<QrtzLocksDO> findList(@RequestBody QrtzLocksDO qrtzLocks) {
    return RowsResponse.ok(qrtzLocksService.findList( qrtzLocks));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<QrtzLocksDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(qrtzLocksService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<QrtzLocksDO> update(@PathVariable("id") Long id, @RequestBody QrtzLocksDO qrtzLocks) {
    qrtzLocks.setId(id);
    return DataResponse.ok(qrtzLocksService.update( qrtzLocks));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(qrtzLocksService.deleteById(id) == 1);
  }

}
